const GKY_TOKEN = 'geek-react-pc-token'
const GKY_CHANNELS = 'geek-react-pc-channels'

/**
 * 存token
 * @param {String} token
 * @returns
 */
export const setToken = (token) =>
  localStorage.setItem(GKY_TOKEN, JSON.stringify(token))

/**
 * 获取token
 * @returns
 */
export const getToken = () => JSON.parse(localStorage.getItem(GKY_TOKEN)) || {}

/**
 * 删除token
 * @returns
 */
export const removeToken = () => localStorage.removeItem(GKY_TOKEN)

/**
 * 判断是否有token
 * @returns
 */
export const hasToken = () => !!getToken().token

export const localChannels = (channels) =>
  localStorage.setItem(GKY_CHANNELS, JSON.stringify(channels))

export const getLocalChannels = () =>
  JSON.parse(localStorage.getItem(GKY_CHANNELS))

export const removeChannels = () => localStorage.removeItem(GKY_CHANNELS)
